package bidsanity

import org.junit.*
import org.codehaus.groovy.grails.plugins.web.taglib.ValidationTagLib

class BidControllerIntegrationTests {
    @Before
    void setUp() {
        // Setup logic here
    }

    @After
    void tearDown() {
        // Tear down logic here
    }

    @Test
    void testFailedBidTooLow() {
        def controller = new BidController()
        def s = new Customer(emailAddress: 'seller@example.org', password: "testing").save(validate: true)
        def b = new Customer(emailAddress: 'bidder@example.org', password: "testing").save(validate: true)
        def l = new Listing(
                name: 'TestListing',
                endDate: new Date() + 10,
                startingBidPrice: 1.0D,
                description: 'a test listing',
                seller: s)
        def newBid =new Bid(bidder: b, listing:  l, amount: 12.0D)
        l.addToBids(newBid)
        l.save(validate: true)
        Assert.assertFalse l.hasErrors()
        Map myParams = ['bidder': b, 'listing': l, amount: '2.0']
        controller.params.putAll(myParams)
        controller.save()
        //probably shouldn't hardcode this but not sure how to access the messages from the integration tests.
        Assert.assertTrue(controller.flash.message == 'Bid of $2.00 was too low.  The bid must be $0.50 more than the highest bid.')
        Assert.assertTrue(controller.response.redirectedUrl == "/listing/show/${l.id}")
    }

}
